using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the Forum class.
	/// </summary>
	[Serializable]
	public partial class ForumCollection : ActiveList<Forum, ForumCollection> 
	{	   
		public ForumCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Forum table.
	/// </summary>
	[Serializable]
	public partial class Forum : ActiveRecord<Forum>
	{
		#region .ctors and Default Settings
		
		public Forum()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Forum(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Forum(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Forum(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Forum", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarForumID = new TableSchema.TableColumn(schema);
				colvarForumID.ColumnName = "ForumID";
				colvarForumID.DataType = DbType.Int32;
				colvarForumID.MaxLength = 0;
				colvarForumID.AutoIncrement = true;
				colvarForumID.IsNullable = false;
				colvarForumID.IsPrimaryKey = true;
				colvarForumID.IsForeignKey = false;
				colvarForumID.IsReadOnly = false;
				colvarForumID.DefaultSetting = @"";
				colvarForumID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarForumID);
				
				TableSchema.TableColumn colvarForumName = new TableSchema.TableColumn(schema);
				colvarForumName.ColumnName = "ForumName";
				colvarForumName.DataType = DbType.String;
				colvarForumName.MaxLength = 255;
				colvarForumName.AutoIncrement = false;
				colvarForumName.IsNullable = true;
				colvarForumName.IsPrimaryKey = false;
				colvarForumName.IsForeignKey = false;
				colvarForumName.IsReadOnly = false;
				colvarForumName.DefaultSetting = @"";
				colvarForumName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarForumName);
				
				TableSchema.TableColumn colvarForumText = new TableSchema.TableColumn(schema);
				colvarForumText.ColumnName = "ForumText";
				colvarForumText.DataType = DbType.String;
				colvarForumText.MaxLength = 2147483647;
				colvarForumText.AutoIncrement = false;
				colvarForumText.IsNullable = true;
				colvarForumText.IsPrimaryKey = false;
				colvarForumText.IsForeignKey = false;
				colvarForumText.IsReadOnly = false;
				colvarForumText.DefaultSetting = @"";
				colvarForumText.ForeignKeyTableName = "";
				schema.Columns.Add(colvarForumText);
				
				TableSchema.TableColumn colvarIdentifierRef = new TableSchema.TableColumn(schema);
				colvarIdentifierRef.ColumnName = "IdentifierRef";
				colvarIdentifierRef.DataType = DbType.String;
				colvarIdentifierRef.MaxLength = 50;
				colvarIdentifierRef.AutoIncrement = false;
				colvarIdentifierRef.IsNullable = true;
				colvarIdentifierRef.IsPrimaryKey = false;
				colvarIdentifierRef.IsForeignKey = false;
				colvarIdentifierRef.IsReadOnly = false;
				colvarIdentifierRef.DefaultSetting = @"";
				colvarIdentifierRef.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIdentifierRef);
				
				TableSchema.TableColumn colvarCourseID = new TableSchema.TableColumn(schema);
				colvarCourseID.ColumnName = "CourseID";
				colvarCourseID.DataType = DbType.Int32;
				colvarCourseID.MaxLength = 0;
				colvarCourseID.AutoIncrement = false;
				colvarCourseID.IsNullable = false;
				colvarCourseID.IsPrimaryKey = false;
				colvarCourseID.IsForeignKey = false;
				colvarCourseID.IsReadOnly = false;
				colvarCourseID.DefaultSetting = @"";
				colvarCourseID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCourseID);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "IsDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = true;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				colvarIsDeleted.DefaultSetting = @"";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("Forum",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ForumID")]
		public int ForumID 
		{
			get { return GetColumnValue<int>("ForumID"); }

			set { SetColumnValue("ForumID", value); }

		}

		  
		[XmlAttribute("ForumName")]
		public string ForumName 
		{
			get { return GetColumnValue<string>("ForumName"); }

			set { SetColumnValue("ForumName", value); }

		}

		  
		[XmlAttribute("ForumText")]
		public string ForumText 
		{
			get { return GetColumnValue<string>("ForumText"); }

			set { SetColumnValue("ForumText", value); }

		}

		  
		[XmlAttribute("IdentifierRef")]
		public string IdentifierRef 
		{
			get { return GetColumnValue<string>("IdentifierRef"); }

			set { SetColumnValue("IdentifierRef", value); }

		}

		  
		[XmlAttribute("CourseID")]
		public int CourseID 
		{
			get { return GetColumnValue<int>("CourseID"); }

			set { SetColumnValue("CourseID", value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>("CreatedOn"); }

			set { SetColumnValue("CreatedOn", value); }

		}

		  
		[XmlAttribute("IsDeleted")]
		public bool? IsDeleted 
		{
			get { return GetColumnValue<bool?>("IsDeleted"); }

			set { SetColumnValue("IsDeleted", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public LMSData.ThreadCollection ThreadRecords()
		{
			return new LMSData.ThreadCollection().Where(Thread.Columns.ForumID, ForumID).Load();
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varForumName,string varForumText,string varIdentifierRef,int varCourseID,DateTime? varCreatedOn,bool? varIsDeleted)
		{
			Forum item = new Forum();
			
			item.ForumName = varForumName;
			
			item.ForumText = varForumText;
			
			item.IdentifierRef = varIdentifierRef;
			
			item.CourseID = varCourseID;
			
			item.CreatedOn = varCreatedOn;
			
			item.IsDeleted = varIsDeleted;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varForumID,string varForumName,string varForumText,string varIdentifierRef,int varCourseID,DateTime? varCreatedOn,bool? varIsDeleted)
		{
			Forum item = new Forum();
			
				item.ForumID = varForumID;
				
				item.ForumName = varForumName;
				
				item.ForumText = varForumText;
				
				item.IdentifierRef = varIdentifierRef;
				
				item.CourseID = varCourseID;
				
				item.CreatedOn = varCreatedOn;
				
				item.IsDeleted = varIsDeleted;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ForumID = @"ForumID";
			 public static string ForumName = @"ForumName";
			 public static string ForumText = @"ForumText";
			 public static string IdentifierRef = @"IdentifierRef";
			 public static string CourseID = @"CourseID";
			 public static string CreatedOn = @"CreatedOn";
			 public static string IsDeleted = @"IsDeleted";
						
		}

		#endregion
	}

}

